package com.novanok.mailtweets.comun;

import twitter4j.Twitter;
import twitter4j.TwitterException;
import twitter4j.TwitterFactory;
import twitter4j.auth.AccessToken;
import twitter4j.auth.RequestToken;
import twitter4j.conf.Configuration;
import twitter4j.conf.ConfigurationBuilder;

public final class TwitterUtil {
 
    private RequestToken requestToken = null;
    private TwitterFactory twitterFactory = null;
    private static final String consumerKey = "awrL9C72GXjVapYodXXPJg2jA";
    private static final String consumerSecret = "9XTlj0iMEX6uHQxM3Om8fZMiGeWPwPby1yLD1CTby8Sses5sGG";
    private Twitter twitter;
 
    public TwitterUtil() {
        ConfigurationBuilder configurationBuilder = new ConfigurationBuilder();
        configurationBuilder.setOAuthConsumerKey(consumerKey);
        configurationBuilder.setOAuthConsumerSecret(consumerSecret);
        Configuration configuration = configurationBuilder.build();
        twitterFactory = new TwitterFactory(configuration);
        twitter = twitterFactory.getInstance();
    }
 
    public TwitterFactory getTwitterFactory()
    {
        return twitterFactory;
    }
 
    public void setTwitterFactory( AccessToken accessToken )
    {
        twitter = twitterFactory.getInstance( accessToken );
    }
 
    public Twitter getTwitter()
    {
        return twitter;
    }

    public RequestToken getRequestToken() {
        if ( requestToken == null ) {
            try {
                requestToken = twitterFactory.getInstance().getOAuthRequestToken("oauth://com.hintdesk.Twitter_oAuth");
            } catch (TwitterException e) {
                e.printStackTrace();
            }
        }
        return requestToken;
    }
 
    static TwitterUtil instance = new TwitterUtil();
 
    public static TwitterUtil getInstance() {
        return instance;
    }

    public void reset() {
        instance = new TwitterUtil();
    }

    public static String getConsumerKey(){
        return consumerKey;
    }

    public static String getConsumerSecret() {
        return consumerSecret;
    }
}